import pytest
from utils import DriverUtil, get_alert_msg
from v5.index_page import IndexTask
from v5.login_page import LoginTask


class TestLogin(object):
    def setup_class(self):
        self.driver = DriverUtil.get_driver()  # 获取浏览器对象
        self.index_task = IndexTask()   # 实例化首页业务层对象
        self.login_task = LoginTask()   # 实例化登录页面业务层对象

    def teardown_class(self):
        DriverUtil.quit_driver()  # 退出浏览器对象

    def setup_method(self):
        self.driver.get("https://hmshop-test.itheima.net/")
        self.index_task.go_to_login()       # 跳转登录

    def teardown_method(self):
        pass

    def test_account_does_not_exist(self):
        '''账号不存在测试方法'''
        self.login_task.login_method("13811110001", "123456", "8888")   # 执行登录

        # 6、获取错误提示信息
        msg = get_alert_msg()
        print("错误信息为：", msg)

    def test_wrong_password(self):
        '''密码错误测试方法'''
        self.login_task.login_method("13800001111", "error", "8888")   # 执行登录

        # 6、获取错误提示信息
        msg = get_alert_msg()
        print("错误信息为：", msg)

if __name__ == '__main__':
    pytest.main(['-s', 'tpshop_login5'])